-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: first version of the Rebalancer with flashloan #109
Conversation
dbb9fff
to
e1b7925
Compare
a463e1a
to
990aaba
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #109 +/- ##
===========================================
- Coverage 100.00% 97.75% -2.25%
===========================================
Files 22 23 +1
Lines 912 936 +24
===========================================
+ Hits 912 915 +3
- Misses 0 21 +21 ☔ View full report in Codecov by Sentry. |
function onFlashLoan( | ||
address initiator, | ||
address, | ||
uint256 amount, | ||
uint256 fee, | ||
bytes calldata data | ||
) external returns (bytes32) { | ||
if (msg.sender != address(FLASHLOAN) || initiator != address(this) || fee != 0) revert NotTrusted(); | ||
uint256 typeAction = abi.decode(data, (uint256)); | ||
address tokenOut; | ||
address tokenIn; | ||
if (typeAction == 1) { | ||
// Increase yield exposure action: we bring in the vault | ||
tokenOut = address(COLLATERAL); | ||
tokenIn = address(VAULT); | ||
} else { | ||
// Decrease yield exposure action: we bring in the collateral | ||
tokenIn = address(COLLATERAL); | ||
tokenOut = address(VAULT); | ||
} | ||
uint256 amountOut = TRANSMUTER.swapExactInput(amount, 0, AGTOKEN, tokenOut, address(this), block.timestamp); | ||
if (typeAction == 1) amountOut = VAULT.deposit(amountOut, address(this)); | ||
else amountOut = VAULT.redeem(amountOut, address(this), address(this)); | ||
uint256 allowance = IERC20(tokenIn).allowance(address(this), address(TRANSMUTER)); | ||
if (allowance < amountOut) | ||
IERC20(tokenIn).safeIncreaseAllowance(address(TRANSMUTER), type(uint256).max - allowance); | ||
uint256 amountStableOut = TRANSMUTER.swapExactInput( | ||
amountOut, | ||
0, | ||
tokenIn, | ||
AGTOKEN, | ||
address(this), | ||
block.timestamp | ||
); | ||
|
||
if (amount > amountStableOut) { | ||
uint256 subsidy = amount - amountStableOut; | ||
orders[tokenIn][tokenOut].subsidyBudget -= subsidy.toUint112(); | ||
budget -= subsidy; | ||
emit SubsidyPaid(tokenIn, tokenOut, subsidy); | ||
} | ||
|
||
return CALLBACK_SUCCESS; | ||
} |
Check notice
Code scanning / Slither
Block timestamp Low
Dangerous comparisons:
- amount > amountStableOut
e9ce80c
to
6127b54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we may do any tokenIn or tokenOut with this contract that come along the way
Not really in this implementation in can only be VAULT or COLLATERAL
6094b11
to
ff8d4e1
Compare
function adjustYieldExposure( | ||
uint256 amountStablecoins, | ||
uint8 increase, | ||
address collateral, | ||
address vault | ||
) external { | ||
if (!TRANSMUTER.isTrustedSeller(msg.sender)) revert NotTrusted(); | ||
FLASHLOAN.flashLoan( | ||
IERC3156FlashBorrower(address(this)), | ||
address(AGTOKEN), | ||
amountStablecoins, | ||
abi.encode(increase, collateral, vault) | ||
); | ||
} |
Check warning
Code scanning / Slither
Unused return Medium
ff8d4e1
to
0267e88
Compare
address(this), | ||
block.timestamp | ||
); | ||
if (amount > amountStableOut) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have a min amount out check
No description provided.